# -*- coding: utf-8 -*-
from odoo import models, api, fields, tools
from odoo.exceptions import UserError
import re


class crop_varieties(models.Model):

    _name = "datcent.crop_varieties"
    _description = "品种"
    _table = "datcent_crop_varieties"
    _order = "sequence"
    _inherit =  ['mail.thread', 'mail.activity.mixin', 'image.mixin']

    sequence = fields.Integer(string="排序",translate = 0)
    name = fields.Char(string="品种名称",translate = 0)
    alias = fields.Char(string="别名",translate = 0)
    latin_name = fields.Char(string="拉丁文名",translate = 0)
    english_name = fields.Char(string="英文名",translate = 0)
    crop_category_id = fields.Many2one(string="作物类别",comodel_name = 'datcent.crop_category',translate = 0)
    crop_id = fields.Many2one(string="作物名称",comodel_name = 'datcent.crop',translate = 0)
    family_genus_id = fields.Many2one(string="科属种",comodel_name = 'datcent.family_genus',translate = 0)
    breed_partner = fields.Char(string="选育单位",domain = [('is_company','=',True)],translate = 0)
    file_no = fields.Char(string="审定/登记编号",translate = 0)
    authorize_type = fields.Selection(string="审定/登记类型",selection = [('1', '国审'), ('2', '省审')],default='1',translate = 0)
    product_date = fields.Date(string="审定/登记年份",translate = 0)
    partner_id = fields.Many2one(string="授权审定/登记单位",comodel_name = 'res.partner',domain = [('is_company','=',True)],translate = 0)
    country_id = fields.Many2one(string="国家",comodel_name = 'res.country',default = lambda self:self.env['res.country'].search([('code','=','CN')]),translate = 0)
    region_id = fields.Many2one(string="省市县区",comodel_name = 'setcent.region',translate = 0)
    variety_source = fields.Char(string="品种来源",translate = 0)
    is_gene_modi = fields.Boolean(string="是否转基因",translate = 0)
    gene_modi_name = fields.Char(string="转基因生物名称",translate = 0)
    is_PO_license = fields.Boolean(string="是否有生产经营许可证",translate = 0)
    is_variety_right = fields.Boolean(string="是否有品种权",translate = 0)
    is_promote_variety = fields.Boolean(string="是否有品种推广权",translate = 0)
    certificate_no = fields.Char(string="证书编号",translate = 0)
    announcement_no = fields.Char(string="公告号",translate = 0)
    author = fields.Char(string="品种权人",translate = 0)
    breeder = fields.Char(string="育种人",translate = 0)
    apply_date = fields.Date(string="申请日期",translate = 0)
    data_source = fields.Text(string="数据来源",translate = 0)
    is_publish_web = fields.Boolean(string="是否允许发布网上",translate = 0)
    image1 = fields.Binary(string="品种照片",translate = 0)
    certificate_image = fields.Binary(string="证书照片",translate = 0)
    approval_opinions = fields.Html(string="审定意见",translate = 0)
    characteristics = fields.Html(string="特征特性",translate = 0)
    disease_resistance = fields.Html(string="抗病鉴定",translate = 0)
    insect_resistance = fields.Html(string="抗虫鉴定",translate = 0)
    quality_results = fields.Html(string="品质分析",translate = 0)
    yeild_results = fields.Html(string="产量水平",translate = 0)
    suitable_area_season = fields.Html(string="适宜种植区域及季节",translate = 0)
    precautions = fields.Html(string="注意事项",translate = 0)
    cultivation_techniques = fields.Html(string="栽培技术要点",translate = 0)
    attachment = fields.Many2many(string="相关附件",comodel_name = 'ir.attachment',translate = 0)
    detail_contents = fields.Html(string="详细说明",translate = 0)
    state = fields.Selection(string="状态",selection = [('1', '草稿'), ('2', '提交'), ('3', '审核')],default='1',translate = 0)

    def button1(self):
        if self.state == '1':
            self.write({'state': '2'})
        # 审核
    def button2(self):
        if self.state == '2':
            self.write({'state': '3'})
        # 退回
    def button3(self):
        if self.state == '2':
            self.write({'state': '1'})

        # 反审核
    def button4(self):
        if self.state == '3':
            self.write({'state': '2'})
